function create_updated_collection(collectionA, objectB) {
  let collectionC=[];
  for (let i=0;i<collectionA.length;)
  {  
  let count=0;
  for (let j=i;j<collectionA.length;j++)
    {
      if(collectionA[i]==collectionA[j])
        {
          count+=1;
        }
    }
  collectionC.push({"key":collectionA[i],"count":count});
  i+=count;
  }
  collectionC.pop();
  collectionC.push({"key":collectionA[collectionA.length-1].substr(0,1),"count":parseInt(collectionA[collectionA.length-1].substr(-1,1))});
  for (let a=0;a<collectionC.length;a++)
    {
      for (let b=0;b<objectB["value"].length;b++)
        {
          if (collectionC[a]["key"]==objectB["value"][b])
            collectionC[a]={"key":collectionC[a]["key"],"count":collectionC[a]["count"]-parseInt(collectionC[a]["count"]/3)}
        }
    }
  return collectionC;
}

module.exports = create_updated_collection;
